package ch.cm.android.teamlearn.gcm;

import android.content.Context;
import android.util.Log;

import com.google.android.gcm.GCMRegistrar;

public class GCMRegistrator {

    public static final String PROJECT_ID = "49073290166";

    private String TAG = "GCMRegistrator";
    private Context mainScreenContext;
    private String registrationID = "";

    public GCMRegistrator(Context context) {
        this.mainScreenContext = context;
    }

    public void registerClient() {

        try {
            GCMRegistrar.checkDevice(mainScreenContext);
            GCMRegistrar.checkManifest(mainScreenContext);
            registrationID = GCMRegistrar.getRegistrationId(mainScreenContext);
            Log.d(TAG, "registrationID: " + registrationID);

            if (registrationID.equals("")) {
                Log.d(TAG, "Client is not Registered, registration in progress");
                GCMRegistrar.register(mainScreenContext, PROJECT_ID);
            } else {
                Log.d(TAG, "Client already registered, id: " + registrationID);
            }

        } catch (Exception e) {
            Log.e(TAG, "" + e.getMessage());
        }
    }

}
